package MonotonicStack;

import com.sun.deploy.util.StringUtils;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

/**
 * @ClassName DailyTemperatures
 * @Description TODO
 * @Author lenovo
 * @Date 2023-08-29 9:37
 * @Version 1.0
 * @Comment Magic. Do not touch.
 * If this comment is removed. the program will blow up
 */
public class DailyTemperatures {

    /**
     * 请根据每日 气温 列表，重新生成一个列表。对应位置的输出为：要想观测到更高的气温，至少需要等待的天数。如果气温在这之后都不会升高，请在该位置用 0 来代替。
     * <p>
     * 例如，给定一个列表 temperatures = [73, 74, 75, 71, 69, 72, 76, 73]，你的输出应该是 [1, 1, 4, 2, 1, 1, 0, 0]。
     * <p>
     * 提示：气温 列表长度的范围是 [1, 30000]。每个气温的值的均为华氏度，都是在 [30, 100] 范围内的整数
     *
     * @param temperatures
     * @return
     */
    public int[] dailyTemperatures(int[] temperatures) {
        int[] res = new int[temperatures.length];
        Deque<Integer> deque = new LinkedList<>();
        deque.push(0);
        for (int i = 1; i < temperatures.length; i++) {
            if (temperatures[deque.peek()] >= temperatures[i]) {
                deque.push(i);
            } else {
                while (!deque.isEmpty() && temperatures[deque.peek()] < temperatures[i]) {
                    res[deque.peek()] = i - deque.peek();
                    deque.pop();
                }
                deque.push(i);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        DailyTemperatures dailyTemperatures = new DailyTemperatures();
        int[] ints = dailyTemperatures.dailyTemperatures(new int[]{73, 74, 75, 71, 69, 72, 76, 73});
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }

        List<String> store = new ArrayList<>();
        store.add("a");
        store.add("b");
        store.add("c");
//        String join = StringUtils.join(store, "','");
        StringBuilder builder = new StringBuilder();
        System.out.println(builder.append("'").append(StringUtils.join(store, "','")).append("'").toString());
        System.out.println(StringUtils.join(store, "','"));
    }
}